package com.augurit.gzcgwsp.ssgd.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwRqSsgdSqbForFx;
import com.augurit.gzcgwsp.ssgd.entity.YwRqSsgdSqb;
import com.augurit.gzcgwsp.ssgd.web.form.YwRqSsgdSqbForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

public class YwRqSsgdSqbConvertor {
	public static YwRqSsgdSqbForm convertVoToForm(YwRqSsgdSqb entity) {
		if (entity == null) return null;
		
		YwRqSsgdSqbForm form = new DozerBeanMapper().map(entity, YwRqSsgdSqbForm.class);
		
		form.setAcceptNo2(entity.getAcceptNo());
		form.setCbyw2(entity.getCbyw());
		form.setCbyw(entity.getCbyw());
		form.setCbyw3(entity.getCbyw());
		form.setCbyw4(entity.getCbyw());
		form.setSjr2(entity.getSjr());
		form.setSqdw2(entity.getSqdw());
		form.setSqrq2(entity.getSqrq());
		if(entity.getSqrq() != null){
			form.setSqrq3(DateUtils.dateTimeToString(entity.getSqrq(), DateUtils.YEAR_MOUTH_DAY_));
			form.setSqrq4(DateUtils.dateTimeToString(entity.getSqrq(), DateUtils.YEAR_MOUTH_DAY_));
		}else{
			form.setSqrq3(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
			form.setSqrq4(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
		}
		
		form.setCurDate(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
		form.setCurDate2(form.getCurDate());
		form.setCurDate3(form.getCurDate());
		form.setSendNotice(entity.getSendNotice());
		
		return form;
	}
	
	public static void convertFormToQyxxForm(YwRqSsgdSqbForm form, YwComQyxxForm qyxxForm) {
	    if (form == null) return;
	    if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        qyxxForm.setId(form.getQyid());
	}
    
    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, YwRqSsgdSqbForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new YwRqSsgdSqbForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQyid(qyxxForm.getId());
    }
	
	public static void convertFormToVo(YwRqSsgdSqbForm form, YwRqSsgdSqb entity) {
	    if (form == null) return;
		if (entity == null) entity = new YwRqSsgdSqb();
		
		new DozerBeanMapper().map(form, entity);
		entity.setSendNotice(form.getSendNotice());
	}
	
	public static List<YwRqSsgdSqbForm> convertVoListToFormList(List<YwRqSsgdSqb> ywRqSsgdSqbList) {
		if(ywRqSsgdSqbList != null && ywRqSsgdSqbList.size() > 0) {
			List<YwRqSsgdSqbForm> ywRqSsgdSqbFormList = new ArrayList<YwRqSsgdSqbForm>();
			for(int i=0; i<ywRqSsgdSqbList.size(); i++) {
				ywRqSsgdSqbFormList.add(convertVoToForm(ywRqSsgdSqbList.get(i)));
			}
			return ywRqSsgdSqbFormList;
		}
		return null;
	}
	
	public static List<YwRqSsgdSqb> convertFormListToVoList(List<YwRqSsgdSqbForm> ywRqSsgdSqbFormList) {
		if(ywRqSsgdSqbFormList != null && ywRqSsgdSqbFormList.size() > 0) {
			List<YwRqSsgdSqb> ywRqSsgdSqbList = new ArrayList();
			for(int i=0; i<ywRqSsgdSqbFormList.size(); i++) {
				YwRqSsgdSqb ywRqSsgdSqb = new YwRqSsgdSqb();
				convertFormToVo(ywRqSsgdSqbFormList.get(i), ywRqSsgdSqb);
				ywRqSsgdSqbList.add(ywRqSsgdSqb);
			}
			return ywRqSsgdSqbList;
		}
		return null;
	}
	
	public static void convertFormToYwRqSsgdSqbForFx(YwRqSsgdSqbForm form, YwRqSsgdSqbForFx entity) {
	    if (form == null) return;
		if (entity == null) entity = new YwRqSsgdSqbForFx();
		if(StringUtils.isNotEmpty(form.getKnsyxyh())){
			entity.setKesyxyh(form.getKnsyxyh());
		}
		if(StringUtils.isNotEmpty(form.getYwlxr())){
			entity.setLxr(form.getYwlxr());
		}
		if(StringUtils.isNotEmpty(form.getSsgdyy())){
			entity.setShyj(form.getSsgdyy());
		}
		if(StringUtils.isNotEmpty(form.getAddress())){
			entity.setSsgddd(form.getAddress());
		}
		if(StringUtils.isNotEmpty(form.getYwlxrtel())){
			entity.setLxrTel(form.getYwlxrtel());
		}
		if(StringUtils.isNotEmpty(form.getYwlxphone())){
			entity.setLxrSj(form.getYwlxphone());
		}
		
		new DozerBeanMapper().map(form, entity);
	}
}